WorkerProcess.GetState Method [IIS 7 and higher]
Returns the run-time state of a worker process.
Syntax
oWorkerProcess.GetState
var workerProcessState = objWorkerProcess.GetState();
Parameters
This method takes no parameters.
Return Value
A uint32 that identifies the application pool state. The return values are shown in the following table.
Return value |
Description |
---|---|
0 |
Indicates that the worker process is starting. |
1 |
Indicates that the worker process is running. |
2 |
Indicates that the worker process is stopping. |
3 |
Indicates that the worker process is unknown. |
Remarks
This method is new to the IIS 7 WMI provider and has no counterpart in IIS 6.0.
Example
The following example returns the state of every worker process in each application pool on a server.
' Connect to the WMI WebAdministration namespace.
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Return all application pools that are present on the server.
Set colAppPools = oWebAdmin.ExecQuery("SELECT * FROM ApplicationPool")
' Return each application pool name.
For Each oAppPool In colAppPools
WScript.Echo oAppPool.Name
WScript.Echo String(Len(oAppPool.Name), "-")
' Get all worker processes in the application pool.
Set oWorkerProcesses = _
oAppPool.Associators_("ApplicationPoolContainsProcess")
' Return each worker process ID and report its state by using
' the GetStateDescription helper function.
For Each oWorkerProcess In oWorkerProcesses
WScript.Echo "Process ID " & oWorkerProcess.ID & _
" is " & GetStateDescription(oWorkerProcess.GetState) & "."
Next
WScript.Echo
Next
' Return the text string that corresponds to the state code.
Function GetStateDescription(StateCode)
Select Case StateCode
Case 0
GetStateDescription = "starting"
Case 1
GetStateDescription = "running"
Case 2
GetStateDescription = "stopping"
Case 3
GetStateDescription = "unknown"
Case Else
GetStateDescription = _
"Attempt to retrieve worker process state failed."
End Select
End Function
Because WorkerProcess is a transient object, the state reported by WMI when the script is run may no longer be valid after some time has elapsed.
Requirements
Type |
Description |
---|---|
Client |
Requires IIS 7 on Windows Vista. |
Server |
Requires IIS 7 on Windows Server 2008. |
Product |
IIS 7 |
MOF file |
WebAdministration.mof |
See Also
Reference
ApplicationPool Class [IIS 7 and higher]